package com.example.myview

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.lifecycleScope
import com.example.myview.coroutineText.ProjectSelectNetWork
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.*
import java.lang.Exception

class MainActivity : AppCompatActivity() {
    private lateinit var launch: Job
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        lifecycle.addObserver(custom_view)
        launch = GlobalScope.launch(Dispatchers.IO) {
            connectNet()
        }
    }

    private suspend fun connectNet() {
        try {
            var bean = ProjectSelectNetWork.select(53)
            if (bean.code == 0) {
                var data = bean.data
                var sb = StringBuffer()
                for (c in data) {
                    sb.append(c.project_name)
                }
                Log.e("connectNet", sb.toString())
            }

        } catch (e: Exception) {

        }
    }

    override fun onDestroy() {
        super.onDestroy()
        launch?.cancel()
    }

}
